export type Commment = {
    com_id: string
    content: string
    reply_count: number
    pubdate: string
    is_followed: boolean
    is_liking: boolean
    like_count: number
    aut_id: string
    aut_name: string
    aut_photo: string
  }
  
  export type Comments = {
    total_count: number
    end_id: string
    last_id: string
    results: Commment[]
  }
  
  // 初始数据
  const initState = {
    comments: {} as Comments,
  }
  type ArticleAction =
  | { type: 'comment/saveComments'; payload: Comments }
  | { type: 'comment/saveComments'; payload: Comments }
  | { type: 'comment/addComments'; payload: Commment };
  
  // 频道 reducer 纯函数
  export default function commentReducer(state = initState, action: ArticleAction) {
    switch (action.type) {
      case 'comment/saveComments':
        return { ...state, comments: action.payload }
        case 'comment/addComments':
          return {
            ...state,
            comments: {
              ...state.comments,
              results: [action.payload, ...state.comments.results],
            },
          };
      default:
        return state
    }
  }